package leecode

import "math"

func beautySum(s string) int {
	var result int
	for i := 0; i < len(s); i++ {
		temp := [26]int{}
		maxCount := 0
		for _, str := range s[i:] {
			temp[str-'a']++
			maxCount = max(maxCount, temp[str-'a'])
			minCount := math.MaxInt
			for j := 0; j < len(temp); j++ {
				if temp[j] > 0 {
					minCount = min(minCount, temp[j])
				}
			}
			result += maxCount - minCount
		}
	}
	return result
}
